library(tidyverse)
dice_list <- c(rep(0.006,73),seq(from = .006, to = 1, length.out = 17))

gacha <- function(x = 0, mercy = 0){
  for(i in 1:90){
    your_pull <- runif(1)
    #print(str_glue('round {i} --- your pull is {your_pull}...\n the odd now is {dice_list[i]}...'))
    up_card <- ifelse(mercy, 1, 0)
    if (your_pull <= dice_list[i] & up_card >= .5){
      return(i)}
    if (your_pull <= dice_list[i]){
      return(i+gacha(mercy = 1))
    }
  }}
k <- map_dbl(1:10000, gacha)
mean(k)
min(k)
max(k)
median(k)

tibble(k = k) |>
  ggplot(aes(k)) + geom_density() + geom_vline(xintercept = 81)

tibble(k = k) |>
  count(k) |>
  slice_max(n)
